package com.hu.gulimallproduct.project.service.impl;

import com.hu.gulimallcommon.utils.Query;
import com.hu.gulimallproduct.project.dao.PmsProductAttrValueDao;
import com.hu.gulimallproduct.project.entity.PmsProductAttrValueEntity;
import com.hu.gulimallproduct.project.service.PmsProductAttrValueService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hu.gulimallcommon.utils.PageUtils;



@Service()
public class PmsProductAttrValueServiceImpl extends ServiceImpl<PmsProductAttrValueDao, PmsProductAttrValueEntity> implements PmsProductAttrValueService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PmsProductAttrValueEntity> page = this.page(
                new Query<PmsProductAttrValueEntity>().getPage(params),
                new QueryWrapper<PmsProductAttrValueEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<PmsProductAttrValueEntity> baseAttrlistforspu(Long spuId) {
        return this.baseMapper.selectList(new QueryWrapper<PmsProductAttrValueEntity>().eq("spu_id",spuId));
    }

    @Override
    public void updateSpuAttr(Long spuId, List<PmsProductAttrValueEntity> entities) {
        //删除这个spuId之前对应的所有属性
        this.baseMapper.delete(new QueryWrapper<PmsProductAttrValueEntity>().eq("spu_id",spuId));
        for (PmsProductAttrValueEntity entity : entities) {
            entity.setSpuId(spuId);
        }
        this.saveBatch(entities);
    }

}